package com.chen.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chen.common.Result;
import com.chen.entity.User;
import com.chen.mapper.UserMapper;
import com.chen.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author personcoder007
 * @since 2022-07-17
 */
@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements IUserService {

    @Autowired
    private UserMapper userMapper;


    /**
     * 分页
     * @param pageNum
     * @param pageSize
     * @param nickname
     * @param username
     * @param address
     * @return
     */
    public IPage<User> selectPage(Integer pageNum, Integer pageSize,
                                  String username, String nickname , String address) {
        IPage<User> page = new Page<User>(pageNum,pageSize);
        QueryWrapper queryWrapper=new QueryWrapper();
//        模糊查询
//        根据昵称查询
        if(!"".equals(nickname)){
            queryWrapper.like("nickname",nickname);
        }
//        根据用户名查询
        if(!"".equals(username)){
            queryWrapper.like("username",username);
        }
//        根据家庭住址查询
        if (!"".equals(address)){
            queryWrapper.like("address",address);
        }
        IPage selectPage = userMapper.selectPage(page, queryWrapper);
        return selectPage;
    }



}
